<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>返件详情页</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
    <link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css"/>
    <script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>
    <script type="text/javascript" src="plug-in/jquery/ajaxfileupload.js"></script>
    <script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
    <script type="text/javascript">
        //编写自定义JS代码
        function lookBackImg(obj) {
            addOneTab('预览', 'cbsServiceController.do?openViewFile&fileid=' + obj.id)
        }

        function checkeNull(obj) {
            //alert("id:"+obj.id)
            //alert("value:"+obj.value)
            var value = obj.value;
            if (value == null || value == '') {
                $('#' + obj.id + 'Err').show();
            } else {
                $('#' + obj.id + 'Err').hide();
            }
        }
    </script>
    <style type="text/css">
        .noSelect {
            border: 0;
            /*display: block;*/
            /*position: relative;*/
            min-height: 1.146667rem;
            line-height: 1.146667rem;
            white-space: nowrap;
            /*width: 100%;*/
            overflow: hidden;
            padding-right: .6rem;
            background-color: #eee;
            background: transparent;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }
    </style>
</head>
<body>
<div style="margin-bottom:10px;">
    <img style="margin-bottom:-7px" src="plug-in/login/images/dispatch bill.png">
    <span class="list-title" id="reTurnCode">${cbsReturnEquipmentPage.code}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span style="font-size:13px;">状态：<span style="color: red">${status}
        <%--<t:dictSelect field="status" clazz="noSelect" readonly="true"
                      typeGroupCode="<%=StaticValue.RETURN_STATUS_Log_Type%>"
                      defaultVal="${cbsReturnEquipmentPage.status}">
        </t:dictSelect>--%>
    </span></span>
</div>

<div class="subtitle">
    <p>关联信息</p>
    <input id="returnId" hidden="hidden" value="${cbsReturnEquipmentPage.id}">
    <table class="nobordertable noborder">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>服务单号CR:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.crCode}
            </td>
            <td class="al_r" width="20%">
                <label>备件申请单号:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.equipmentApplyId.recordId}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>发货单号:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.deliverCode}
            </td>
            <td class="al_r" width="20%">
                <label>SR:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.srCode}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>SO:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.soCode}
            </td>
            <td class="al_r" width="20%">

            </td>
            <td width="30%">

            </td>
        </tr>
        </tbody>
    </table>
</div>
<div class="subtitle">
    <p>返件信息</p>
    <c:forEach items="${cbsReturnEquipmentDetailEntities}" var="r" varStatus="i">
        <input type="hidden" name="rd_${i}" id="rd_${i}" value="${r.id}">
        <div style="margin-top:20px; width: 98%; margin: 0px auto;"><span
                style="font-weight: bold;">返件：${i.index+1}</span></div>
        <div class="l-div">
            <table class="nobordertable noborder" style="border: none;">
                <tbody>
                <tr>
                    <td class="al_r" width="20%">
                        <label>类型:</label>
                    </td>
                    <td width="30%">
                        <span id="typeDesc_${i}">${r.typeId.typeDesc}</span>
                    </td>
                    <td class="al_r" width="20%">
                        <label>备件号:</label>
                    </td>
                    <td width="30%">
                        <span id="item_${i}">${r.item}</span>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%">
                        <label>状态:</label>
                    </td>
                    <td width="30%">
                        <span>
                            <c:if test="${r.returnEquipmentStatus==1}">DOA</c:if>
                            <c:if test="${r.returnEquipmentStatus==2}">好件</c:if>
                            <c:if test="${r.returnEquipmentStatus==3}">坏件</c:if>
                        </span>
                    </td>
                    <td class="al_r" width="20%">
                        <label hidden="hidden">序列号:</label>
                    </td>
                    <td width="30%">
                        <span hidden="hidden" id="snForGCS_${i.index}">${r.sn}</span>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <label>备注:</label>
                    </td>
                    <td width="30%">
                            ${r.memo}
                    </td>
                    <td class="al_r" width="20%" valign="top">
                        <label hidden="hidden">二维码:</label>
                    </td>
                    <td width="30%">
                        <span hidden="hidden" id="equipmentErcodeForGCS_${i.index}">${r.equipmentErcode}</span>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </c:forEach>
</div>
<div class="subtitle">
    <p>取货联系人信息</p>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>姓名:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.name}
            </td>
            <td class="al_r" width="20%">
                <label>电话:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.phone}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>取货地址:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.sheng.territoryName}&emsp;${cbsReturnEquipmentPage.shi.territoryName}&emsp;${cbsReturnEquipmentPage.address}
            </td>
            <td class="al_r" width="20%">
                <label>影院名称:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.cinemaName}
            </td>
        </tr>
        </tbody>
    </table>
</div>
<div class="subtitle">
    <p>物流</p>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>预计取货时间:<font color="red">*</font></label>
            </td>
            <td width="30%">
                <c:if test="${cbsReturnEquipmentPage.status==3 || cbsReturnEquipmentPage.status==4 ||cbsReturnEquipmentPage.status==5 }">
                    ${cbsReturnEquipmentPage.pickupTime}
                </c:if>
                <c:if test="${cbsReturnEquipmentPage.status==2}">
                    <input class="Wdate" value="${cbsReturnEquipmentPage.pickupTime}" onblur="checkeNull(this)"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="expectTime" id="expectTime">
                </c:if>
                <span id="expectTimeErr" style="color: red;font-size: 10px" hidden="hidden">预计取货时间不能为空</span>
            </td>
            <td class="al_r" width="20%">
                <label>预计回库时间:<font color="red">*</font></label>
            </td>
            <td width="30%">
                <c:if test="${cbsReturnEquipmentPage.status==3 || cbsReturnEquipmentPage.status==4 ||cbsReturnEquipmentPage.status==5 }">
                    ${cbsReturnEquipmentPage.backwarehouseTime}
                </c:if>
                <c:if test="${cbsReturnEquipmentPage.status==2}">
                    <input class="Wdate" value="${cbsReturnEquipmentPage.backwarehouseTime}" onblur="checkeNull(this)"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="expectTime" id="backwarehouseTime">
                </c:if>
                <span id="backwarehouseTimeErr" style="color: red;font-size: 10px" hidden="hidden">预计回库时间不能为空</span>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>物流运单号:<c:if test="${cbsReturnEquipmentPage.status==3}">
                    <sapn style="color: red">*</sapn>
                </c:if></label>
            </td>
            <td width="30%">
                <input name="code" id="code" value="${cbsReturnEquipmentPage.logisticsCode}"
                       onkeyup="checkeNull(this)"/>
                <span id="codeErr" style="color: red;font-size: 10px" hidden="hidden">物流运单号不能为空</span>
            </td>
            <td class="al_r" width="20%">

            </td>
            <td width="30%">

            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%" valign="top">
                <label>备注:</label>
            </td>
            <td colspan="3">
                <c:if test="${cbsReturnEquipmentPage.status==3 || cbsReturnEquipmentPage.status==4 ||cbsReturnEquipmentPage.status==5 }">
                    ${cbsReturnEquipmentPage.logisticsMemo}
                </c:if>
                <c:if test="${cbsReturnEquipmentPage.status==2}">
                    <textarea maxlength="255" style="width: 100%; height: 60px;" id="logisticsMemo"
                              name="logisticsMemo">${cbsReturnEquipmentPage.logisticsMemo}</textarea>
                </c:if>

            </td>
        </tr>
        </tbody>
    </table>
    <div style="text-align: center;" id="subBut"
         <c:if test="${cbsReturnEquipmentPage.status==3 || cbsReturnEquipmentPage.status==4 ||cbsReturnEquipmentPage.status==5 }">hidden="hidden"</c:if> >
        <a href="#" class="easyui-linkbutton l-btn"
           onclick="submitReturnEquipment('${cbsReturnEquipmentPage.id}')">提交</a>
    </div>
</div>
<c:set var="type" value="<%=StaticValue.RETURN_STATUS_Log_Type_3 %>"/>
<c:if test="${cbsReturnEquipmentPage.status eq type }">
    <div class="subtitle">
        <p>入库信息</p>
        <c:forEach items="${cbsReturnEquipmentDetailEntities}" var="r" varStatus="i">
            <input hidden name="id_${i.index}" value="${r.id}" id="id_${i.index}">
            <div style="margin-top:20px; width: 98%; margin: 0px auto;">
                <span style="font-weight: bold;">返件：${i.index+1}</span></div>
            <div class="l-div">
                <table class="nobordertable noborder" style="border: none;">
                    <tbody>
                    <tr>
                        <td class="al_r" width="20%">
                            <label>类型:</label>
                        </td>
                        <td width="30%">
                            <span id="typeDescReturn_${i.index}"
                                  name="typeDescReturn_${i.index}">${r.typeId.typeDesc}</span>
                        </td>
                        <td class="al_r" width="20%">
                            <label>备件号:<font color="red">*</font></label>
                        </td>
                        <td width="30%">
                            <input type="text" hidden="hidden" id="${i.index}isTrack">
                            <c:if test="${r.typeDes=='未知备件'}">
                                <input id="item${i.index}" onkeyup="hideErr('itemReturn_${i.index}',this)">
                                <select name="itemReturn_${i.index}" id="itemReturn_${i.index}" hidden="hidden" onchange="checkeNull(this);getIsTrack('${i.index}');getItem('${i.index}')">
                                    <option value="">--请选择备件号--</option>
                                    <c:forEach items="${equipmentItemMap[r.id]}" var="item">
                                        <option value="${item.id}">${item.item}</option>
                                    </c:forEach>
                                </select>
                            </c:if>
                            <c:if test="${r.typeDes!='未知备件'}">
                                <input hidden="hidden" id="item${i.index}" onkeyup="hideErr('itemReturn_${i.index}',this)">
                                <select name="itemReturn_${i.index}" id="itemReturn_${i.index}" onchange="checkeNull(this);getIsTrack('${i.index}');getItem('${i.index}')">
                                    <option value="">--请选择备件号--</option>
                                    <c:forEach items="${equipmentItemMap[r.id]}" var="item">
                                        <option value="${item.id}">${item.item}</option>
                                    </c:forEach>
                                </select>
                            </c:if>
                            <span id="itemReturn_${i.index}Err" style="color: red;font-size: 10px" hidden="hidden">备件号不能为空</span>
                                <%-- <input id="itemReturn_${i.index}" value="${r.returnEquipmentDetailId.itemId.item}" name="itemReturn_${i.index}"/>--%>
                        </td>
                    </tr>
                    <tr>
                        <td class="al_r" width="20%">
                            <label>物料号:</label>
                        </td>
                        <td width="30%">
                            <input type="text" name="matterNum_${i.index}" id="matterNum_${i.index}">
                        </td>
                        <td class="al_r" width="20%">
                            <label>序列号:<font class="${i.index}isTrack" hidden="hidden" color="red">*</font></label>
                        </td>
                        <td width="30%">
                            <input type="text" onkeyup="checkeNull(this)" id="snReturn_${i.index}"/><span
                                id="snReturn_${i.index}Err" hidden="hidden"
                                style="font-size: 10px;color: red">序列号不能为空</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="al_r" width="20%">
                            <label>版本号:</label>
                        </td>
                        <td width="30%">
                            <input type="text" name="verCode_${i.index}" id="verCode_${i.index}"/>
                        </td>
                        <td class="al_r" width="20%">
                            <label>二维码:<font class="${i.index}isTrack" hidden="hidden" color="red">*</font></label>
                        </td>
                        <td width="30%">
                            <input type="text" onkeyup="checkeNull(this)" name="equipmentErcode_${i.index}"
                                   id="equipmentErcode_${i.index}"/><span id="equipmentErcode_${i.index}Err"
                                                                          hidden="hidden"
                                                                          style="font-size: 10px;color: red">二维码不能为空</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="al_r" width="20%" valign="top">
                            <label>仓库:<font color="red">*</font></label>
                        </td>
                        <td width="30%">
                            <select name="warehouse_${i.index}" id="warehouse_${i.index}" onchange="checkeNull(this)">
                                <option value="">--请选择仓库--</option>
                                <c:forEach items="${wareList}" var="ware">
                                    <option value="${ware.id}">${ware.name}</option>
                                </c:forEach>
                            </select>
                            <span id="warehouse_${i.index}Err" style="color: red;font-size: 10px"
                                  hidden="hidden">仓库不能为空</span>
                        </td>
                        <td class="al_r" width="20%" valign="top">
                            <label>库位:<font color="red">*</font></label>
                        </td>
                        <td width="30%">
                            <select name="warehousePosition_${i.index}" id="warehousePosition_${i.index}"
                                    onchange="checkeNull(this)">
                                <option value="">--请选择库位--</option>
                                <c:forEach items="${kuweiList}" var="kuwei">
                                    <option value="${kuwei.typecode}">${kuwei.typename}</option>
                                </c:forEach>
                            </select>
                            <span id="warehousePosition_${i.index}Err" style="color: red;font-size: 10px"
                                  hidden="hidden">库位不能为空</span>
                                <%--<input name="warehousePosition_${i.index}" value="" id="warehousePosition_${i.index}">--%>
                        </td>
                    </tr>
                    <tr>
                        <td class="al_r" width="20%" valign="top">
                            <label>备件照片:<font class="${i.index}open" hidden="hidden" color="red">*</font></label>
                        </td>
                        <td width="30%">
                            <input type="text" hidden="hidden" value="${r.fileId}" id="photoNameBack_${i.index}"
                                   name="photoNameBack_${i.index}"/>
                            <input type="button" id="photoNameBacks_${i.index}" name="photoNameBacks_${i.index}"
                                   value="上传附件"/>
                            <c:if test="${not empty  r.photoName}">
                                <c:forEach items="${backFileList}" var="backlFile">
                                    <c:if test="${backlFile.businessChildType==b.id}">
                                        <%--<a  style="color: #0e90d2"  onclick="lookImg('${backlFile.id}')">${backlFile.oldFileName}</a>--%>
                                        <a style="color: blue;text-decoration: underline"
                                           href="fileUploadController.do?downLoadFile&fileLogId=${backlFile.id}">$${backlFile.oldFileName}</a>
                                    </c:if>
                                </c:forEach>
                            </c:if>
                        </td>
                        <td class="al_r" width="20%" valign="top">
                            <label>开箱检查:<font color="red">*</font></label>
                        </td>
                        <td width="30%">
                            <input type="text" hidden="hidden" id="${i.index}open">
                            <select id="open_${i.index}" onchange="openCheck('${i.index}');checkeNull(this)">
                                <option value="">--请选择--</option>
                                <c:forEach items="${openTypeList}" var="openType">
                                    <option value="${openType.typecode}">${openType.typename}</option>
                                </c:forEach>
                            </select>
                            <span id="open_${i.index}Err" style="color: red;font-size: 10px"
                                  hidden="hidden">开箱检查结果不能为空</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="al_r" width="20%" valign="top">
                            <label>备注:<font class="${i.index}open" hidden="hidden" color="red">*</font></label>
                        </td>
                        <td colspan="3">
                            <textarea style="width: 100%; height: 60px;" name="memo_${i.index}" maxlength="200"
                                      id="memo_${i.index}"></textarea>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </c:forEach>
        <div style="text-align: center;">
            <a href="#" class="easyui-linkbutton l-btn" onclick="submit('${cbsReturnEquipmentPage.id}')">入库</a>
        </div>
        <div>
            <span id="doCompareTime" hidden="hidden" style="color: red;">入库延迟，请选择延迟原因.</span>
            <table class="nobordertable noborder" style="border: none;">
                <tbody>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <span style="color: red">*</span><label>延迟原因:</label>
                    </td>
                    <td width="30%">
                        <select id="unqualified" name="unqualified">
                            <option value="">--请选择延迟原因--</option>
                            <option value="物流原因"
                                    <c:if test="${cbsReturnEquipmentPage.unqualified=='物流原因'}">selected="selected"</c:if>>
                                物流原因
                            </option>
                            <option value="非物流原因"
                                    <c:if test="${cbsReturnEquipmentPage.unqualified=='非物流原因'}">selected="selected"</c:if>>
                                非物流原因
                            </option>
                                <%--<option value="客户推迟"
                                        <c:if test="${cbsReturnEquipmentPage.unqualified=='客户推迟'}">selected="selected"</c:if>>
                                    客户推迟
                                </option>
                                <option value="货物属性"
                                        <c:if test="${cbsReturnEquipmentPage.unqualified=='货物属性'}">selected="selected"</c:if>>
                                    货物属性
                                </option>
                                <option value="发货时间延迟"
                                        <c:if test="${cbsReturnEquipmentPage.unqualified=='发货时间延迟'}">selected="selected"</c:if>>
                                    发货时间延迟
                                </option>
                                <option value="当地安全库存不足"
                                        <c:if test="${cbsReturnEquipmentPage.unqualified=='当地安全库存不足'}">selected="selected"</c:if>>
                                    当地安全库存不足
                                </option>
                                <option value="巴可原因"
                                        <c:if test="${cbsReturnEquipmentPage.unqualified=='巴可原因'}">selected="selected"</c:if> >
                                    巴可原因
                                </option>
                                <option value="其他"
                                        <c:if test="${cbsReturnEquipmentPage.unqualified=='其他'}">selected="selected"</c:if> >
                                    其他
                                </option>--%>
                        </select>
                    </td>
                    <td class="al_r" width="20%" valign="top">

                    </td>
                    <td width="30%">

                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <span style="color: red">*</span><label>延迟备注:</label>
                    </td>
                    <td colspan="3">
                        <textarea style="width: 100%; height: 60px;" maxlength="255" id="unqualifiedMemo"
                                  name="unqualifiedMemo"></textarea>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</c:if>
<div class="subtitle">
    <p>日志</p>
    <table class="ftable">
        <tbody>
        <tr>
            <th>操作人</th>
            <th>时间</th>
            <th>描述</th>
        </tr>
        <c:forEach items="${cbsHandleLogEntities}" var="i">
            <tr>
                <td>${i.createName}</td>
                <td><fmt:formatDate value="${i.createDate}" type="date"
                                    pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
                <td>${i.description}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
</body>
<script>
    $(function () {

        //编辑回显
        var unqualified = '${cbsReturnEquipmentPage.unqualified}';
        /* if(unqualified!=''||unqualified!=null){
             $("#doCompareTime").css("display", "block");
         }*/


        var returuId = $('#returnId').val()
        var rd_ = $("[id^=rd_]");  //返件明细id
        rd_.each(function (i, item) {
            var photoNameBack = '#photoNameBacks_' + i;
            $(photoNameBack).uploadify({
                buttonText: '上传文件',
                progressData: 'speed',
                multi: true,
                height: 20,
                width: 60,
                overrideEvents: ['onDialogClose'],
                queueID: 'instructionfile',
                /*fileTypeDesc: '文件格式:*.png',
                fileTypeExts: '*.png;*.jpg', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc*/
                fileTypeDesc: '文件格式:',
                fileTypeExts: '*', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc
                fileSizeLimit: '50MB',
                swf: 'plug-in/uploadify/uploadify.swf',
                uploader: 'fileUploadController.do?uploadFileBack&businessKey=' + returuId + '&childKey=' + item.value,
                onUploadStart: function () {
                    lockmask(true, '请稍等,导入中...');
                },
                onUploadSuccess: function (file, data) {
                    lockmask(false);
                    var fileBean = $.parseJSON(data).attributes;
                    console.log("fileBean:" + fileBean.obj)
                    var html = '<span name="fileIda" id="filedId' + i + '">' +
                        '<span class="color-blue" id="' + fileBean.fileKey + '" >' + fileBean.name + '</span>&nbsp;&nbsp; ' +
                        '<span style="cursor: pointer;" onclick=\'delFile("' + fileBean.fileKey + '","' + i + '")\'>删除</span>&emsp;' +
                        '</span>';
                    $("#photoNameBack_" + i).after(html);
                    $("#photoNameBack_" + i).val(fileBean.fileKey);
                    tip("上传成功！");
                }, onFallback: function () {
                    tip("您未安装FLASH控件，无法上传文件！请安装FLASH控件后再试");
                }, onSelectError: function (file, errorCode, errorMsg) {
                    switch (errorCode) {
                        case -100:
                            tip("上传的文件数量已经超出系统限制的" + $('#instruction').uploadify('settings', 'queueSizeLimit') + "个文件！");
                            break;
                        case -110:
                            tip("文件 [" + file.name + "] 大小超出系统限制的" + $('#instruction').uploadify('settings', 'fileSizeLimit') + "大小！");
                            break;
                        case -120:
                            tip("文件 [" + file.name + "] 大小异常！");
                            break;
                        case -130:
                            tip("文件 [" + file.name + "] 类型不正确！");
                            break;
                    }
                }
            });

        });

    });

    function delFile(id, i) {
        $.ajax({
            url: "fileUploadController.do?delFileReturn",
            data: {
                "id": id
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            async: false,
            success: function (data) {
                if (!data.success) {
                    tip(data.msg);
                    return false;
                } else {
                    $("#photoNameBack_" + i).hide();
                    $("#filedId" + i).remove();
                    tip("删除成功！");
                }
            }
        });
    }

    /*提交预约取货时间*/
    function submitReturnEquipment(id) {
        var expectTime = $("#expectTime").val();
        var backwarehouseTime = $("#backwarehouseTime").val();
        var code = $("#code").val();
        var logisticsMemo = $("#logisticsMemo").val();
        if (expectTime == null || expectTime == '') {
            $("#expectTimeErr").show()
            parent.window.tip("请填写预计取货时间")
            return false;
        }
        if (backwarehouseTime == null || backwarehouseTime == '') {
            $("#backwarehouseTimeErr").show()
            parent.window.tip("请填写预计回库时间")
            return false;
        }

        $.ajax({
            url: "cbsReturnEquipmentController.do?submitReturnEquipment",
            data: {
                "id": id,
                "expectTime": expectTime,
                "backwarehouseTime": backwarehouseTime,
                "code": code,
                "logisticsMemo": logisticsMemo
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function (data) {
                // addOneTab("物流返件管理","cbsReturnEquipmentController.do?cbsReturnEquipmentWL");
                // closetab('返件详情');
                var Recode = $("#reTurnCode").text();
                var tabName = "返件详情" + Recode;
                setTimeout("addOneTab('物流返件管理','cbsReturnEquipmentController.do?cbsReturnEquipmentWL');", 1000);
                setTimeout("closetab('" + tabName + "')", 1000);
                tip(data.msg);
            }
        });
    }

    //入库
    function submit(id) {
        var flag = false;
        /*如果入库日期（入库详情表创建日期：入库时当前时间）
        大于预计回库日期，需提示performance未达标，并选择未达标原因，填写备注*/
        var unqualified = "";
        var unqualifiedMemo = "";
        if (id != null && id != '') {
            $.ajax({
                url: "cbsReturnEquipmentController.do?doCompareTime",
                data: {"id": id},
                cache: false,
                async: false,
                dataType: 'json',
                type: 'POST',
                success: function (data) {
                    if (!data.success) {
                        $("#doCompareTime").show();
                        unqualified = $("#unqualified").val();
                        unqualifiedMemo = $("#unqualifiedMemo").val();
                        if (unqualified != null && unqualified != "" && unqualifiedMemo != null && unqualifiedMemo != "") {
                            flag = true;
                        } else {
                            $('#doCompareTime').show()
                            parent.window.tip("请选择延迟原因和填写备注");
                        }
                    } else {
                        flag = true;
                        if (data.msg == "ERROR") {
                            tip("备件已入库，请刷新后再进行其他操作！");
                            flag = false;
                        }
                    }
                }
            });
        }
        if (flag) {
            var flag2 = true;
            var rd_ = $("[id^=id_]");  //返件明细id
            var rds = "";
            var mainId = id;
            var code = $("#code").val();
            if (code == null || code == '') {
                $("#codeErr").show()
                parent.window.tip("请填写物流运单号")
                return false;
            }
            var unqualified = unqualified;
            var unqualifiedMemo = unqualifiedMemo;
            var datalist = new Array();
            rd_.each(function (i, item) {
                var object = new Object();

                object.id = $("#id_" + i).val().trim();
                object.typeDesc = $("#typeDescReturn_" + i).val().trim();
                object.item = $("#itemReturn_" + i).val();
                object.itemIn = $('#item' + i).val();
                object.matterNum = $("#matterNum_" + i).val().trim(); //wu liao
                object.sn = $("#snReturn_" + i).val().trim();
                object.verCode = $("#verCode_" + i).val().trim();
                object.equipmentErcode = $("#equipmentErcode_" + i).val().trim();
                object.photoNameBack = $("#photoNameBack_" + i).val().trim();
                object.warehousePosition = $("#warehousePosition_" + i).val();
                object.warehouse = $("#warehouse_" + i).val();
                object.memo = $("#memo_" + i).val().trim();
                object.openCheck = $("#open_" + i).val();
                object.openErr = $("#" + i + 'open').val();
                object.isTrack = $('#' + i + 'isTrack').val();
                // object.unqualified = unqualified;
                // object.unqualifiedMemo = unqualifiedMemo;
                datalist.push(object);

                if ($('#item' + i).val() == null || $('#item' + i).val() == "") {
                    $("#itemReturn_" + i + "Err").show()
                    parent.window.tip("请填写备件号")
                    flag2 = false;
                    return false;
                }

                //判断是否序列号追踪
                if ($('#' + i + 'isTrack').val() == 'is' && ($("#snReturn_" + i).val() == null || $("#snReturn_" + i).val() == "")) {//是序列号追踪
                    $("#snReturn_" + i + "Err").show()
                    parent.window.tip("请填写序列号")
                    flag2 = false;
                    return false;
                }
                if ($('#' + i + 'isTrack').val() == 'is' && ($("#equipmentErcode_" + i).val() == null || $("#equipmentErcode_" + i).val() == "")) {//是序列号追踪
                    $("#equipmentErcode_" + i + "Err").show()
                    parent.window.tip("请填写二维码")
                    flag2 = false;
                    return false;
                }

                if ($('#' + i + 'isTrack').val() == 'is' && $("#snReturn_" + i).val() != $("#snForGCS_" + i).text().trim() && $("#photoNameBack_" + i).val() == "") {
                    parent.window.tip("返件" + (i + 1) + "入库序列号和工程师返件序列号不一致，请上传序列号照片")
                    flag2 = false;
                    return false;

                }
                if ($('#' + i + 'isTrack').val() == 'is' && $("#equipmentErcode_" + i).val() != $("#equipmentErcodeForGCS_" + i).text().trim() && $("#photoNameBack_" + i).val() == "") {
                    parent.window.tip("返件" + (i + 1) + "入库二维码和工程师返件二维码不一致，请上传二维码照片")
                    flag2 = false;
                    return false;
                }


                if ($("#warehousePosition_" + i).val() == null || $("#warehousePosition_" + i).val() == "") {
                    $("#warehousePosition_" + i + "Err").show()
                    parent.window.tip("请选择返件库位")
                    flag2 = false;
                    return false;
                }

                if ($("#warehouse_" + i).val() == null || $("#warehouse_" + i).val() == "") {
                    $("#warehouse_" + i + "Err").show()
                    parent.window.tip("请选择仓库")
                    flag2 = false;
                    return false;
                }


                if ($("#open_" + i).val() == null || $("#open_" + i).val() == "") {
                    $("#open_" + id + "Err").show()
                    parent.window.tip("请选择开箱检查结果")
                    flag2 = false;
                    return false;
                }

                //判断开箱检查是否异常
                if ($("#" + i + 'open').val() == 'yc' && ($("#photoNameBack_" + i).val() == null || $("#photoNameBack_" + i).val() == "")) {
                    parent.window.tip("请上传照片")
                    flag2 = false;
                    return false;
                }
                if ($("#" + i + 'open').val() == 'yc' && ($("#memo_" + i).val() == null || $("#memo_" + i).val() == "")) {
                    parent.window.tip("请填写备注")
                    flag2 = false;
                    return false;
                }

            });
            console.log("datalist:" + datalist)

            if (flag2) {
                if (rd_ == '' || rd_ == null) {
                    tip("没有要返件的信息，请核对后再返件！");
                } else {
                    $.ajax({
                        url: "cbsReturnEquipmentController.do?doReturnEquipmentWL&code=" + code,
                        data: {
                            "datalist": JSON.stringify(datalist),
                            "mainId": mainId,
                            "unqualified": unqualified,
                            "unqualifiedMemo": unqualifiedMemo
                        },
                        cache: false,
                        dataType: 'json',
                        type: 'POST',
                        success: function (data) {
                            if (data.success) {
                                tip(data.msg);
                                var Recode = $("#reTurnCode").text();
                                var tabName = "返件详情" + Recode;
                                addOneTab("物流返件管理", "cbsReturnEquipmentController.do?cbsReturnEquipmentWL");
                                setTimeout("closetab('" + tabName + "')", 1000);
                            } else {
                                tip(data.msg);
                            }
                        }
                    });
                }
            }


        }
        console.info("返件明细datalist==" + datalist);

    }


    function getItem(id) {
        var itemValue = $('#itemReturn_' + id).val()
        $('#item' + id).val(itemValue)
    }


    function getIsTrack(id) {
        var itemId = $('#itemReturn_' + id).val()
        $.ajax({
            url: "cbsReturnEquipmentController.do?getItmById",
            data: {"id": itemId},
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function (data) {
                var item = data.obj
                if (item.isTrack == '1') {
                    $('#' + id + 'isTrack').val('is')
                    $('.' + id + 'isTrack').show()
                } else {
                    $('#' + id + 'isTrack').val('')
                    $('.' + id + 'isTrack').hide()
                    $("#equipmentErcode" + id + "Err").hide()
                    $("#sn" + id + "Err").hide()
                }
            }
        });
    }

    function openCheck(id) {
        var openValue = $('#open_' + id).val()
        if (openValue != '<%= StaticValue.open_zc%>' && openValue != '') {
            $('.' + id + 'open').show()
            $('#' + id + 'open').val('yc')
        } else {
            $('.' + id + 'open').hide()
            $('#' + id + 'open').val('')
        }
    }
</script>
</html>
